test(gherkin): cover event.test.before/after payload regression#5582
Merged
Conversation
Adds three layers of coverage for the bug fixed in 770749e (gherkin beforeEach/afterEach emitting event.test.before with a placeholder test when the hook Context lacked .ctx.currentTest): * Unit (test/unit/bdd_test.js): six tests in a new "Gherkin hook events" block that drive the codeceptjs.before/after hooks with a mock Mocha Context and assert the real scenario title and tags reach event.test.before, event.test.after, the Before/After step-definition hooks, and that done is forwarded. * Runner (test/runner/bdd_test.js + test/data/sandbox): a capture plugin and codecept.bdd.events.js config that serialize event payloads to a temp JSON file so a spawned runner asserts the real @important/@very tags reach listeners end-to-end. * Acceptance (test/acceptance/gherkin/before_hook.feature + steps.js): a new Background+tagged feature whose Then step verifies both the BDD Before() hook and a direct event.test.before listener captured the real scenario. Also flips setup/teardown to prefer suite.ctx.currentTest over suite.currentTest, restoring the regular Scenario path while keeping the BDD fallback. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added tests covering #5580
Summary
Adds three layers of test coverage for the bug fixed in #5580 (
770749e1), where the GherkinbeforeEachhook emittedevent.test.beforewith a placeholder test (title"...", emptytags) because the asyncWrapper readsuite.ctx.currentTestfrom a Mocha hook Context that only hadcurrentTestdirectly. The regression silently broke every listener ofevent.test.before(@testomatio/reporter,screenshot,heal,customReporter,aiTrace,screencast,globalTimeout,globalRetry,retryFailedStep, the workers IPC bridge, …) for BDD scenarios.test/unit/bdd_test.js) — 6 new tests in aGherkin hook eventsblock. They drive thecodeceptjs.before/codeceptjs.afterhooks with a synthetic Mocha hook Context ({ currentTest }) and assert the real scenario title and tags reachevent.test.before,event.test.after, theBefore/Afterstep-definition hooks, thatdoneis forwarded exactly once, and that the event orderingtest.before → test.started → test.passed → test.afteris preserved.test/runner/bdd_test.js+test/data/sandbox/) — new capture plugin (support/capture_test_before.js) and config (codecept.bdd.events.js) serializeevent.test.before/afterpayloads to a temp JSON file. A spawned runner asserts the real@important/@verytags and scenario title reach listeners end-to-end.test/acceptance/gherkin/before_hook.feature+steps.js) — newBackground+ tagged scenario. The Then step verifies both the BDDBefore()hook and a directevent.test.beforelistener captured the real scenario title/tags.Also flips the
suite?.ctx?.currentTest ?? suite?.currentTestprecedence insetup/teardownso the regular Scenario path keeps usingctx.currentTestwhile the BDD hook Context still falls back tocurrentTest.Verified the new tests catch the regression: reverting
setup/teardownto the pre-fixenhanceMochaTest(suite?.ctx?.currentTest)makes 2/6 unit tests, the runner test, and the acceptance test fail with the placeholder"..."title. Restoring the fix makes them all pass.Test plan
npx mocha test/unit/bdd_test.js --timeout 10000— 24 passing (6 new + 18 existing)npx mocha test/runner/bdd_test.js --timeout 60000 --grep "emits event.test.before"— 1 passing./bin/codecept.js run --config test/acceptance/codecept.Playwright.js --grep "@hookCapture" --verbose— passes against the PHP test app on:8000lib/mocha/asyncWrapper.jsto the pre-fix code causes all three new layers to fail with the placeholder"..."title; restoring the fix makes them pass~/projects/testomatio/examples/codeceptjs-cucumber/— scenarios now report with real titles and@T…tags🤖 Generated with Claude Code